<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
Movie[] issuedMovies = null;
String status1 = null;
try{
MovieBussinessProxy movieBI = new MovieBussinessProxy();  
long userid = (Long) session.getAttribute("MembershipId");
movieBI.setEndpoint(ServiceEndPoints.MovieEndPoint);
issuedMovies = movieBI.getUserIssuedMovies(userid);
session.setAttribute("issuedMovies", issuedMovies);
issuedMovies=(Movie[])session.getAttribute("issuedMovies");
}catch(UserHasNotIssuedAnyMovieException m){
	status1 =  "There are no movies on your account to return";
	}
%>
<%@page import="com.beans.Movie"%>
<%@page import="com.bussiness.MovieBussinessProxy" %>
<%@page import="com.constants.ServiceEndPoints" %>
<%@page import="com.exceptions.UserHasNotIssuedAnyMovieException" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<script type="text/javascript">
function validateRate(){
	var flag = true;
	var rate=document.forms["returnmovieForm"]["Rate"].value;
	
	var numericExpression = /^[0-9]+$/;
	document.all("rateerror").innerHTML  = "";
	
		if (!rate.match(numericExpression) )
		{
			
			document.all("rateerror").innerHTML  = "Enter a valid rating (1 bad to 5 Excellent)";
			flag = false;
		}
		return flag;
}
</script>
<body>
<form id="returnmovieForm" name="returnmovieForm" method="POST" action="ReturnMovieServlet" >
<div class ="inputColumn" id = "CartItems"  
				style="text-align: left; border: none; margin: auto;">	
				<div style="text-align:center;font-size:2em;font-family: sans serif;">
				<%String status = (String)request.getAttribute("ServerMessage");
			if(status != null){
			%>
			<label style="size: 25; color: green"><%=status%></label>	<%
			
			}else if(status1 != null){ %>
			<label style="size: 25; color: green"><%=status1%></label> <%} %>	
			<label id="rateerror"  style="size: 32; color: red"></label> 
			</div>
			
			<table align="center" border="1" style="border-style: dashed">
			<%
			if(issuedMovies != null)
			{
			%>
				<tr>
				<th align="center" style="color:red" bordercolor="red">Click to Return</th>
				<th align="center" style="color:red" bordercolor="red">Movie</th>
				<th align="center" style="color:red" bordercolor="red">Banner</th>
				<th align="center" style="color:red" bordercolor="red">Date Rented</th>
				<th align="center" style="color:red" bordercolor="red">Rating(Bad1-Excellent5)</th>
				</tr>
				<% 
				
				for(int i=0;i<issuedMovies.length;i++)
				{
				%>
				<tr bordercolor="black" >
				  <td bordercolor="black">
					 	<button type="submit" style="height: 25px; width: 50px; background-color:black" name="movieid"><%=issuedMovies[i].getMovieId()%></button>
					</td>
				  <td bordercolor="black">
					 	<label id ="MovieName" style="size: 25;"><%=issuedMovies[i].getMovieName()%></label> 
					</td>
					<td bordercolor="black">
					 	<label id ="MovieBanner" style="size: 25;"><%=issuedMovies[i].getMovieBanner()  %></label> 
					</td>
					<td bordercolor="black">
					 	<label id ="Rent" style="size: 25;"><%=issuedMovies[i].getRentdate()  %></label> 
					</td>
					<td bordercolor="black">
						<input type="text" name="Rate" size="3" maxlength="1" style="background-color:#eeeeee;">
					</td>
				</tr>
				<%
				}
				%>
				
			</table>
			
				<%			
			}
			
			%>
	</div>
</form>
</body>
</html>